package com.zhl.hadoop.mapreduce.sort;

import lombok.Data;
import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2020-10-29 11:17
 **/
@Data
public class SortBean implements WritableComparable<SortBean> {

	private String name;
	private int score;

	@Override
	public int compareTo(SortBean other) {
		int i = this.name.compareTo(other.name);
		if(i == 0){
			return score - other.score;
		}
		return i;
	}

	@Override
	public void write(DataOutput dataOutput) throws IOException {
		dataOutput.writeUTF(name);
		dataOutput.writeInt(score);
	}

	@Override
	public void readFields(DataInput dataInput) throws IOException {
		name = dataInput.readUTF();
		score = dataInput.readInt();
	}
}
